package com.core.db.require;

import java.sql.SQLException;
import java.util.List;

import com.core.db.condition.Condition;

class Delect extends BaseRequire
{
	private String table;
	private Condition cond;
	private List< ColumnDescribe > describes;

	public Delect( String table, List< ColumnDescribe > describes, Condition cond )
	{
		this.table = table;
		this.describes = describes;
		this.cond = cond;
	}

	@Override
	public String sql() throws SQLException
	{
		if ( cond == null || table == null || table.length() == 0 )
		{
			throw new SQLException( "No table to be found to be operated on" );
		}
		StringBuffer buffer = new StringBuffer();
		buffer.append( "DELETE FROM " ).append( table );
		buffer.append( " " ).append( assembleWhere( cond ) );
		return buffer.toString();
	}

	@Override
	public List< ColumnDescribe > getColumnDescribes()
	{
		return describes;
	}

	@Override
	public Condition getCondition()
	{
		return cond;
	}
}
